package com.caigou.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.caigou.service.BusinessProcessService;

import jiliang.purchase.demo.BusinessProcessing;
import jiliang.purchase.demo.CriteriaBusinessProcess;
import jiliang.purchase.demo.PersonObject;
import sch.jl.caigou.utils.Page;

public class myShenqingServlet extends HttpServlet {

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	
	private BusinessProcessService BPS = new BusinessProcessService();
	private CriteriaBusinessProcess CBP = null;
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		HttpSession session = request.getSession();
		request.setCharacterEncoding("utf-8");
		PersonObject PO = new PersonObject();
		PO = (PersonObject)session.getAttribute("Person");
		
		String xmid = null;
		String bh = null;
		String xingming = PO.getXingming();
		String start = null;
		String endtime = null;
		String zt = null;
		String pageNo = request.getParameter("page");
		int pageNum = 1;
		String returnTitle = "";
		
		if(pageNo != null && !pageNo.equals(""))
		{
			pageNum = Integer.valueOf(pageNo);
		}
		
		if(request.getParameter("xmid")!=null && !request.getParameter("xmid").equals("0"))
		{
			xmid = request.getParameter("xmid");
		}
		
		if(request.getParameter("cbh")!=null && !request.getParameter("cbh").equals(""))
		{
			bh = request.getParameter("cbh");
			returnTitle+=bh+"|";
		}
		else
		{
			returnTitle+="a"+"|";
		}
		
		if(request.getParameter("xingming")!=null && !request.getParameter("xingming").equals(""))
		{
			xingming = request.getParameter("xingming");
			returnTitle+=xingming+"|";
		}
		else
		{
			returnTitle+="b"+"|";
		}
		
		if(request.getParameter("starttime")!=null && !request.getParameter("starttime").equals(""))
		{
			start = request.getParameter("starttime");
			returnTitle+=start+"|";
		}
		else
		{
			returnTitle+="c"+"|";
		}
		if(request.getParameter("endtime")!=null && !request.getParameter("endtime").equals(""))
		{
			endtime = request.getParameter("endtime");
			returnTitle+=endtime+"|";
		}
		else
		{
			returnTitle+="d"+"|";
		}
		if(request.getParameter("zt")!=null && !request.getParameter("zt").equals("0"))
		{
			zt = request.getParameter("zt");
			returnTitle+=zt;
		}
		else
		{
			returnTitle+="0";
		}
		//System.out.println(returnTitle);
		CBP = new CriteriaBusinessProcess(xmid,bh,xingming,start,endtime,zt,pageNum);
		////System.out.println(PO.getJs_id());
		Page<BusinessProcessing> list =new Page<BusinessProcessing>();
		list = BPS.getData(",20,",PO.getXingming(),CBP);
		
		List<BusinessProcessing> overInfo2 = new ArrayList<BusinessProcessing>();
		
		overInfo2 = BPS.getPDF2(PO.getXingming(), CBP,",20,");

		list.setTotalItemNumber(list.getTotalItemNumber()+overInfo2.size());
		list.getList().addAll(0,overInfo2);
		list.setList(BPS.getPageList(list.getList(), list.getPageNo()));
		
		for(int i=0;i<list.getList().size();i++)
		{
			if(list.getList().get(i).getLast_lc().contains("不通过"))
			{
				list.getList().get(i).setBz_mc("不通过");
			}
		}
		
		request.setAttribute("BusinessProcess", list);
		//request.setAttribute("overInfo", overInfo);
		//request.setAttribute("overInfo2", overInfo2);
		//request.setAttribute("overInfo3", overInfo3);
		request.setAttribute("returnTitle", returnTitle);
		request.getRequestDispatcher("myshenqing.jsp").forward(request, response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request,response);
	}

}
